//
//  CitySubVC.m
//  BrushFace
//
//  Created by Harry on 16/1/24.
//  Copyright © 2016年 Zzz. All rights reserved.
//
#import "UserInfoVC.h"
#import "CitySubVC.h"
#import "MeRequest.h"
@interface CitySubVC ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation CitySubVC

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.navBar setTitle:@"城市"];
    [self.navBar setLeftBtn:NAV_BAR_LEFT_BTN_TYPE_BLUE];
    _table.delegate = self;
    _table.dataSource = self;
    //_subCitys = [[NSArray alloc]init];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
       return  1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
        return _subCitys.count;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    
        return @"全部";
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellName = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
//        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    
   
        NSDictionary *dic = [_subCitys objectAtIndex:indexPath.row];
        cell.textLabel.text = dic[@"name"];
    
       return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (_VCType == cityLive1)
    {
        NSDictionary *datadic = [_subCitys objectAtIndex:indexPath.row];
        NSMutableDictionary *params = [NSMutableDictionary dictionary];
        [params setObject:_proCode forKey:@"liveprovince"];
        [params setObject:datadic[@"value"] forKey:@"livecity"];
        [MeRequest sendUserDataWithType:address AndUserData:params success:^(NSDictionary *dic)
         {
             dispatch_async(dispatch_get_main_queue(), ^{
                 NSString *string = [NSString stringWithFormat:@"%@",dic[@"result"]];
                 if ([string intValue]==1)
                 {
                     NSArray *array = self.navigationController.childViewControllers;
                     NSString *str = [NSString stringWithFormat:@"%@-%@",_proName,datadic[@"name"]];
                     
                     UserInfoVC *viewVC = [array objectAtIndex:array.count-3];
                     viewVC.liveCity = str;
                     [self.navigationController popToViewController:viewVC animated:YES];
                 }});

         } error:^(NSError *error) {
             
         }];

    }
    else if (_VCType == cityHome1)
    {
        NSDictionary *datadic = [_subCitys objectAtIndex:indexPath.row];
        NSMutableDictionary *params = [NSMutableDictionary dictionary];
        [params setObject:_proCode forKey:@"homeprovince"];
        [params setObject:datadic[@"value"] forKey:@"homecity"];

        [MeRequest sendUserDataWithType:homeAddress AndUserData:params success:^(NSDictionary *dic)
         {
             dispatch_async(dispatch_get_main_queue(), ^{
            NSString *string = [NSString stringWithFormat:@"%@",dic[@"result"]];
            if ([string intValue]==1)
            {
                NSArray *array = self.navigationController.childViewControllers;
                
                NSString *str = [NSString stringWithFormat:@"%@-%@",_proName,datadic[@"name"]];
                
                UserInfoVC *viewVC = [array objectAtIndex:array.count-3];
                viewVC.homeTown = str;
                [self.navigationController popToViewController:viewVC animated:YES];
            }});
            

         } error:^(NSError *error) {
             
         }];

    }
    
   }




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
